<?php
namespace app\controllers\api\post;

use fate\http\Request;
use app\models\Posts;
use app\libs\LibUser;

// 软删除
class DeleteController extends \fate\web\PureController {

    public function run() {
        // 是否登录
        $uid = LibUser::getLoginUid();
        if('' === $uid) {
            $this->ajaxReturn(null, 200001);
            exit;
        }

        $req = Request::getInstance();

        $id = $req->getParameter('id');
        if(!is_numeric($id)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        // 有无权限修改 兼顾检查文章是否存在
        $model = new Posts();
        $belong = $model->isBelongTo($id, $uid);
        if(!$belong) {
            $this->ajaxReturn(null, 200002);
            exit;
        }

        $model->block($id, 2);

        $this->ajaxReturn(null);
    }

}
